﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

public partial class index : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        else
        {
            String user = Session["username"].ToString();
            String connString = "server=localhost;database=test;uid=root;pwd=123456";
            MySqlConnection conn = new MySqlConnection(connString);
            conn.Open();
            String sqlselect = "select mainteam from test.webuser where username = '" + user + "';";
            MySqlCommand mycommand = new MySqlCommand(sqlselect, conn);
            MySqlDataReader mdr = mycommand.ExecuteReader();
        if (mdr.Read())
        {
            Session["team"] = mdr["mainteam"].ToString();
        }
        }
        if (Session["team"] == null|| Session["team"].ToString() == "")
        {
            Response.Write("<script>alert('你的主队是？完善个人信息吧！');location.href='http://localhost:50015/personal.aspx';</script>");
        }
        else
        {
            Label1.Text = "欢迎" + Session["username"].ToString();
        }
            

    }

    protected void toresetpw(object sender, EventArgs e)
    {
        Response.Redirect("http://localhost:50015/test.aspx", true);
    }



    protected void ibt1_Click(object sender, ImageClickEventArgs e)
    {
        String theuser = TextBox1.Text;
        String mainteam = "查询失败";
        String age = "查询失败";
        String sex = "查询失败";
        String t = "查询失败";
        String connString = "server=localhost;database=test;uid=root;pwd=123456";
        MySqlConnection conn = new MySqlConnection(connString);
        conn.Open();
        String sqlselect = "select * from test.webuser where username = '" + theuser + "';";
        MySqlCommand mycommand = new MySqlCommand(sqlselect, conn);
        MySqlDataReader mdr = mycommand.ExecuteReader();
        if (mdr.Read())
        {
            sex=mdr["sex"].ToString();
            age=mdr["age"].ToString();
            mainteam=mdr["mainteam"].ToString();
            t = mdr["time"].ToString();
            Response.Write("<script>alert('用户：" + theuser + " \\r\\n性别：" + sex + " \\r\\n年龄：" + age + " \\r\\n主队是:" + mainteam + "\\r\\n上一次登录时间：" + t + "');window.location='http://localhost:50015/Login.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('没这个人')</script>");
        }
        conn.Close();


    }
}